//
//  MyPreferencesViewController.m
//  League
//
//  Created by 博宇 李 on 2018/1/22.
//  Copyright © 2018年 ciyuanjuzhen. All rights reserved.
//

#import "MyPreferencesViewController.h"
#import "TableViewCell.h"
#import "TTRangeSlider.h"
#import "MyProfileViewController.h"
#import "PGGDropView.h"
#import "PickerListViewController.h"
#import "ProdileModel.h"
#import "MyPreferencesViewController.h"
#import "WaitForAuditViewController.h"
#import "ProfileManager.h"
#import "UserInfomation.h"
#import "MyPerfrenceModel.h"

#define kTitleFontSize 14
#define kTextFiledBgColor [UIColor colorWithRed:250/255.0 green:250/255.0 blue:250/255.0 alpha:1]
@interface MyPreferencesViewController ()<UITableViewDataSource,UITableViewDelegate,TTRangeSliderDelegate,PGGDropDelegate>
{
    NSInteger segmentLookIndex;
    NSInteger segmentDistanceIndex;
    
    NSInteger saveAgeMin;
    NSInteger saveAgeMax;
    
    NSInteger saveHeightMin;
    NSInteger saveHeightMax;
    
    NSBundle *bundle ;
    NSString *cityNameLab;
    
    NSMutableArray *cityList ;
    NSInteger selectCityIndex;
}
@property(strong , nonatomic)UITableView *setupTableView;
@property (strong, nonatomic) TTRangeSlider *ageSlider ;
@property (strong, nonatomic) TTRangeSlider *HeightSlider ;
@property(strong,nonatomic)PGGDropView * dropView;
@property (strong, nonatomic) NSMutableArray *cityArray;
@property (strong, nonatomic) ProdileModel *preferEducation;
@property (strong, nonatomic) ProdileModel *religion;
@property (strong, nonatomic) ProfileManager *maneger;

@end

@implementation MyPreferencesViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    self.cityArray = [NSMutableArray array];
    self.maneger = [ProfileManager shareManager];
    
    segmentLookIndex = 0;
    segmentDistanceIndex = 0;
    
    saveAgeMin = 20;
    saveAgeMax = 60;
    selectCityIndex = 0;
    saveHeightMin = 140 ;
    saveHeightMax = 210 ;
    cityNameLab = @"";
    if (self.isRegister == YES) {
        NSLog(@"从注册页过来的");
    }
    else
    {
        NSLog(@"不是注册页");
        
    }
    if (@available(iOS 11.0, *)) {
        self.setupTableView.contentInsetAdjustmentBehavior = UIScrollViewContentInsetAdjustmentNever;
    } else {
        self.automaticallyAdjustsScrollViewInsets = NO;
    }
    [InternationalControl initUserLanguage];//初始化应用语言
    bundle = [InternationalControl bundle];
    self.title = [bundle localizedStringForKey:@"Preferences" value:nil table:@"hello"];
    [self tableVIew];
    
    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(PickerValue:) name:kPickerNotifoStr object:nil];
    //获取城市
    [self getCities];

}

- (void)getCities {
    NSDictionary *dic = @{
                          @"parentid":@(0),
                          @"typename":@"LocationCity"
                          };
    NSString *urlStr = [NSString stringWithFormat:@"%@%@",kFirstUrl,kGetDictionary];
    NSLog(@"urlStr:%@",urlStr);
    [DataContrller PostRequestUrl:urlStr Param:dic requestSuccess:^(NSDictionary *backDic) {
        NSLog(@"backDic:%@",backDic);
        if ([backDic[@"returnCode"] integerValue] == 200) {
            for (NSDictionary *city in backDic[@"obj"]) {
                ProdileModel *model = [[ProdileModel alloc] initWithDictionary:city error:nil];
                if (model != nil) {
                    [self.cityArray addObject:model];
                }
            }
            [self.setupTableView reloadData];
            if (self.isRegister == NO) {
                [self getPerfenrece];
            }
        } else {
            
        }
    } requestFail:^(NSString *backErrorStr) {
        
        NSLog(@"backErrorStr:%@",backErrorStr);
        
    }];
}

- (void)getPerfenrece {
    NSDictionary *dic = @{
                          @"pk":[UserInfomation shareManager].pk
                          };
    NSString *urlStr = [NSString stringWithFormat:@"%@%@",kFirstUrl,kGetPerfenrece];
    NSLog(@"urlStr:%@",urlStr);
    [DataContrller PostRequestUrl:urlStr Param:dic requestSuccess:^(NSDictionary *backDic) {
        NSLog(@"backDic:%@",backDic);
        if ([backDic[@"returnCode"] integerValue] == 200) {
            MyPerfrenceModel *model = [[MyPerfrenceModel alloc] initWithDictionary:backDic[@"obj"] error:nil];
            segmentLookIndex = model.sex;
            saveAgeMin = model.agemin <= 20 ? 20 : model.agemin;
            saveAgeMax = model.agemax <= model.agemin ? saveAgeMin + 1 : model.agemax;
            saveHeightMin = model.heightmin;
            saveHeightMax = model.heightmax == 0 ? model.heightmin + 1 : model.heightmax;
            if (self.religion == nil) {
                self.religion = [[ProdileModel alloc] init];
                self.religion._id = model.religion;
                self.religion.categoryDesc = model.religionStr;
                self.religion.categoryName = model.religionStr;
            }
            if (self.preferEducation == nil) {
                self.preferEducation = [[ProdileModel alloc] init];
                self.preferEducation._id = model.education;
                self.preferEducation.categoryDesc = model.educationStr;
                self.preferEducation.categoryName = model.educationStr;
            }
            for (int i=0; i<self.cityArray.count; i++) {
                ProdileModel *prodileModel = self.cityArray[i];
                if ([model.location isEqualToString:prodileModel._id]) {
                    selectCityIndex = i;
                }
            }
            [self.setupTableView reloadData];
        } else {
            
        }
    } requestFail:^(NSString *backErrorStr) {
        
    }];
}

- (void)PickerValue:(NSNotification *)notification{
    if ([notification.userInfo[@"index"] intValue] == 4) {
        NSLog(@"从4回来");
        self.preferEducation = notification.userInfo[@"data"];
    }
    if ([notification.userInfo[@"index"] intValue] == 5) {
        NSLog(@"从5回来");
        self.religion = notification.userInfo[@"data"];
    }
    [self.setupTableView reloadData];
}
- (void)tableVIew
{

    self.setupTableView = [[UITableView alloc] initWithFrame:CGRectMake(0, 0, self.view.width, self.view.height)];//指定位置大小
    
    [self.setupTableView setDelegate:self];//指定委托
    
    [self.setupTableView setDataSource:self];//指定数据委托
    self.setupTableView.estimatedRowHeight = 0;
    self.setupTableView.estimatedSectionHeaderHeight = 0;
    self.setupTableView.estimatedSectionFooterHeight = 0;
    self.setupTableView.separatorStyle = UITableViewCellSeparatorStyleNone;
    [self.view addSubview:self.setupTableView];//加载tableview
    
    [self.view addSubview:self.setupTableView];
}
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
    return 1;
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    
    return  7;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    
//    TableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"TableViewCell"];
//    if (!cell) {
//        cell = [[TableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:@"TableViewCell"];
//        cell.selectionStyle = UITableViewCellSelectionStyleNone;
//        cell.width = tableView.width;
//    }
    static NSString *CellIdentifier = @"TableViewCell";
    // 通过indexPath创建cell实例 每一个cell都是单独的
    UITableViewCell *cell = [tableView cellForRowAtIndexPath:indexPath];
    // 判断为空进行初始化  --（当拉动页面显示超过主页面内容的时候就会重用之前的cell，而不会再次初始化）
    if (!cell) {
        cell = [[UITableViewCell alloc]initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:CellIdentifier];
        cell.selectionStyle = UITableViewCellSelectionStyleNone;
        cell.width = tableView.width;
    }
//    cell.testLab.text = @"123";

    if(indexPath.row == 0)
    {
        UILabel *title = [[UILabel alloc] initWithFrame:CGRectMake(0, 0, cell.width/3.5, kCellHeight)];
        title.text = [bundle localizedStringForKey:@"LookingFor" value:nil table:@"hello"];
        title.textAlignment = NSTextAlignmentCenter;
        title.adjustsFontSizeToFitWidth = YES;
        title.font=[UIFont fontWithName:kFontName size:kTitleFontSize];
        [cell addSubview:title];
        
        NSArray *array = [NSArray arrayWithObjects:[bundle localizedStringForKey:@"Women" value:nil table:@"hello"],[bundle localizedStringForKey:@"Men" value:nil table:@"hello"],[bundle localizedStringForKey:@"Both" value:nil table:@"hello"], nil];
        //初始化UISegmentedControl
        UISegmentedControl *segment = [[UISegmentedControl alloc]initWithItems:array];
        //设置frame
        segment.frame = CGRectMake(0, 0, cell.width-title.width-10, kCellHeight*0.5);
        segment.center = CGPointMake(title.x+title.width+segment.width/2, kCellHeight/2);
        segment.selectedSegmentIndex = segmentLookIndex;
        segment.tag = 100;
        //控件渲染色(也就是外观字体颜色)
        segment.tintColor = kAppColor;
        [segment addTarget:self action:@selector(change:) forControlEvents:UIControlEventValueChanged];
        //添加到视图
        [cell addSubview:segment];
        
    }
    else if (indexPath.row == 1)
    {
        UILabel *title = [[UILabel alloc] initWithFrame:CGRectMake(0, 0, cell.width/3.5, kCellHeight)];
        title.text = [bundle localizedStringForKey:@"Age" value:nil table:@"hello"];
        title.textAlignment = NSTextAlignmentCenter;
        title.adjustsFontSizeToFitWidth = YES;
        title.font=[UIFont fontWithName:kFontName size:kTitleFontSize];
        [cell addSubview:title];
//
        self.ageSlider = [[TTRangeSlider alloc] initWithFrame: CGRectMake(0, 0, cell.width-title.width, kCellHeight*0.5) :20 andselectedMini:saveAgeMin andmaxV:100 andselectedMaxi:saveAgeMax];
        self.ageSlider.center = CGPointMake(title.x+title.width+self.ageSlider.width/2, kCellHeight/2);
        self.ageSlider.delegate = self;
        self.ageSlider.tag = 1;
        [cell addSubview:self.ageSlider];
        self.ageSlider.minValue = 20;
        self.ageSlider.maxValue = 100;
        self.ageSlider.selectedMinimum = saveAgeMin;
        self.ageSlider.selectedMaximum = saveAgeMax;
        
    }
    
    else if (indexPath.row == 2)
    {
        UILabel *title = [[UILabel alloc] initWithFrame:CGRectMake(0, 0, cell.width/3.5, kCellHeight)];
        title.text = [bundle localizedStringForKey:@"Height" value:nil table:@"hello"];
        title.textAlignment = NSTextAlignmentCenter;
        title.adjustsFontSizeToFitWidth = YES;
        title.font=[UIFont fontWithName:kFontName size:kTitleFontSize];
        [cell addSubview:title];
        //
        self.HeightSlider = [[TTRangeSlider alloc] initWithFrame:CGRectMake(0, 0, cell.width-title.width, kCellHeight) :0 andselectedMini:saveHeightMin andmaxV:200 andselectedMaxi:saveHeightMax];
        self.HeightSlider.center = CGPointMake(title.x+title.width+self.HeightSlider.width/2, kCellHeight/2);
        self.HeightSlider.delegate = self;
        self.HeightSlider.tag = 2;
        [cell addSubview:self.HeightSlider];
        self.HeightSlider.minValue = 0;
        self.HeightSlider.maxValue = 200;
        self.HeightSlider.selectedMinimum = saveHeightMin;
        self.HeightSlider.selectedMaximum = saveHeightMax;
       
    }
    else if (indexPath.row == 3)
    {
        UILabel *title = [[UILabel alloc] initWithFrame:CGRectMake(0, 0, cell.width/3.5, kCellHeight)];
        title.text =[bundle localizedStringForKey:@"Distance" value:nil table:@"hello"];
        title.textAlignment = NSTextAlignmentCenter;
        title.adjustsFontSizeToFitWidth = YES;
        title.font = [UIFont fontWithName:kFontName size:kTitleFontSize];
        [cell addSubview:title];
        
        UILabel *infoLab = [[UILabel alloc] initWithFrame:CGRectMake(0, 0, cell.width-title.width-10, kCellHeight*0.5)];
        infoLab.center = CGPointMake(title.x+title.width+infoLab.width/2, kCellHeight/2);
        if (self.cityArray.count != 0) {
            ProdileModel *model = self.cityArray[selectCityIndex];
            NSString *lan = [InternationalControl userLanguage];
            if([lan isEqualToString:@"en"]){//判断当前的语言，进行改变
                infoLab.text = model.categoryDesc;
            } else {
                infoLab.text = model.categoryName;
            }
        } else {
            infoLab.text = [bundle localizedStringForKey:@"NoPreference" value:nil table:@"hello"];
        }
        infoLab.textAlignment = NSTextAlignmentCenter;
        infoLab.font=[UIFont fontWithName:kFontName size:kTitleFontSize];
        [cell addSubview:infoLab];
//        title.text = cityNameLab;
//        NSArray *array = [NSArray arrayWithObjects:@"城市1",@"城市2",@"城市3", nil];
//        //初始化UISegmentedControl
//        UISegmentedControl *segment = [[UISegmentedControl alloc]initWithItems:array];
//        //设置frame
//        segment.frame = CGRectMake(0, 0, cell.width-title.width-10, kCellHeight*0.5);
//        segment.center = CGPointMake(title.x+title.width+segment.width/2, kCellHeight/2);
//        segment.selectedSegmentIndex = segmentDistanceIndex;
//        segment.tag = 101;
//        //控件渲染色(也就是外观字体颜色)
//        segment.tintColor = kAppColor;
//
//        [segment addTarget:self action:@selector(change:) forControlEvents:UIControlEventValueChanged];
//        //添加到视图
//        [cell addSubview:segment];
    }
    /*
    else if (indexPath.row == 4)
    {
        UILabel *title = [[UILabel alloc] initWithFrame:CGRectMake(0, 0, cell.width/3.5, kCellHeight)];
        title.text = [bundle localizedStringForKey:@"Ethnicity" value:nil table:@"hello"];
        title.font=[UIFont fontWithName:kFontName size:kTitleFontSize];
        title.textAlignment = NSTextAlignmentCenter;
        title.adjustsFontSizeToFitWidth = YES;
        [cell addSubview:title];
        
        UILabel *ethnicityTextLab = [[UILabel alloc] initWithFrame:CGRectMake(0, 0, cell.width-title.width-10, kCellHeight*0.5)];
        ethnicityTextLab.center = CGPointMake(title.x+title.width+ethnicityTextLab.width/2, kCellHeight/2);
        ethnicityTextLab.backgroundColor = kTextFiledBgColor;
        ethnicityTextLab.textAlignment = NSTextAlignmentCenter;
        ethnicityTextLab.textColor = [UIColor blackColor];
        ethnicityTextLab.text = [bundle localizedStringForKey:@"NoPreference" value:nil table:@"hello"];
       ethnicityTextLab.font=[UIFont fontWithName:kFontName size:kTitleFontSize];
        ethnicityTextLab.textAlignment = NSTextAlignmentCenter;
        [cell addSubview:ethnicityTextLab];
    }
     */
    else if (indexPath.row == 4)
    {
        UILabel *title = [[UILabel alloc] initWithFrame:CGRectMake(0, 0, cell.width/3.5, kCellHeight)];
        
        title.textAlignment = NSTextAlignmentCenter;
        title.text = [bundle localizedStringForKey:@"Education" value:nil table:@"hello"];
        title.adjustsFontSizeToFitWidth = YES;
        title.font=[UIFont fontWithName:kFontName size:kTitleFontSize];
        [cell addSubview:title];
        
        UILabel *educationTextLab = [[UILabel alloc] initWithFrame:CGRectMake(0, 0, cell.width-title.width-10, kCellHeight*0.5)];
        educationTextLab.center = CGPointMake(title.x+title.width+educationTextLab.width/2, kCellHeight/2);
        educationTextLab.backgroundColor = kTextFiledBgColor;
        educationTextLab.textColor=[UIColor blackColor];
        if (self.preferEducation == nil) {
            educationTextLab.text = [bundle localizedStringForKey:@"NoPreference" value:nil table:@"hello"];
        } else {
            NSString *lan = [InternationalControl userLanguage];
            if([lan isEqualToString:@"en"]){//判断当前的语言，进行改变
                educationTextLab.text = self.preferEducation.categoryDesc;
            } else {
                educationTextLab.text = self.preferEducation.categoryName;
            }
        }
        educationTextLab.textAlignment = NSTextAlignmentCenter;
        educationTextLab.font=[UIFont fontWithName:kFontName size:kTitleFontSize];
        [cell addSubview:educationTextLab];
    }
    else if (indexPath.row == 5)
    {
        UILabel *title = [[UILabel alloc] initWithFrame:CGRectMake(0, 0, cell.width/3.5, kCellHeight)];
        title.text = [bundle localizedStringForKey:@"Religion" value:nil table:@"hello"];
        title.textAlignment = NSTextAlignmentCenter;
        title.adjustsFontSizeToFitWidth = YES;
        title.font = [UIFont fontWithName:kFontName size:kTitleFontSize];
        [cell addSubview:title];
        
        UILabel *religionTextLab = [[UILabel alloc] initWithFrame:CGRectMake(0, 0, cell.width-title.width-10, kCellHeight*0.5)];
        religionTextLab.center = CGPointMake(title.x+title.width+religionTextLab.width/2, kCellHeight/2);
        religionTextLab.backgroundColor = kTextFiledBgColor;
        religionTextLab.textColor = [UIColor blackColor];
//        religionTextLab.text = [bundle localizedStringForKey:@"NoPreference" value:nil table:@"hello"];
        
        if (self.religion == nil) {
            religionTextLab.text = [bundle localizedStringForKey:@"NoPreference" value:nil table:@"hello"];
        } else {
            NSString *lan = [InternationalControl userLanguage];
            if([lan isEqualToString:@"en"]){//判断当前的语言，进行改变
                religionTextLab.text = self.religion.categoryDesc;
            } else {
                religionTextLab.text = self.religion.categoryName;
            }
        }
        
        religionTextLab.textAlignment = NSTextAlignmentCenter;
        religionTextLab.font=[UIFont fontWithName:kFontName size:kTitleFontSize];
        [cell addSubview:religionTextLab];
    }
    else if (indexPath.row == 6){
        UIButton *nextBtn = [[UIButton alloc] initWithFrame:CGRectMake(0, 0, cell.width/1.5, kCellHeight/2)];
        nextBtn.center = CGPointMake(cell.width/2, kCellHeight/2);
        nextBtn.backgroundColor = kAppColor;
        [nextBtn setTitle:[bundle localizedStringForKey:@"Next" value:nil table:@"hello"] forState:UIControlStateNormal];
        [nextBtn addTarget:self action:@selector(next:) forControlEvents:UIControlEventTouchDown];
        nextBtn.titleLabel.font=[UIFont fontWithName:kFontName size:kTitleFontSize];
        nextBtn.layer.masksToBounds = YES;
        nextBtn.layer.cornerRadius = 8;
        [cell addSubview:nextBtn];
        if (self.isRegister == NO) {
            [nextBtn setTitle:[bundle localizedStringForKey:@"over" value:nil table:@"hello"] forState:UIControlStateNormal];
        }
    }
    return cell;
    
}

-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    NSLog(@"row:%@ - section:%@",@(indexPath.row) , @(indexPath.section));
    /*
       if (indexPath.row == 4)
       {
           PickerListViewController *pickerVc = [[PickerListViewController alloc] init];
           pickerVc.isRadio = NO;
           pickerVc.index = indexPath.row;
           [self presentViewController:pickerVc animated:YES completion:^{
               
           }];
       }
    else
     */
        if (indexPath.row == 3)
    {
        [self.dropView removeFromSuperview];
        NSString *lan = [InternationalControl userLanguage];
        NSMutableArray *titleArray = [NSMutableArray array];
        if([lan isEqualToString:@"en"]){//判断当前的语言，进行改变
            for (ProdileModel *model in self.cityArray) {
                [titleArray addObject:model.categoryDesc];
            }
        } else {
            for (ProdileModel *model in self.cityArray) {
                [titleArray addObject:model.categoryName];
            }
        }
        self.dropView = [[PGGDropView alloc] initWithFrame:CGRectMake(0, 0 ,self.view.width, 300) withTitleArray:titleArray];
        self.dropView.center = CGPointMake(self.view.width/2, self.view.height/2);
        self.dropView.backgroundColor = kTextFiledBgColor;
        [self.dropView beginAnimation];
        self.dropView.delegate = self;
        [self.view addSubview:self.dropView];
    }
   else if (indexPath.row == 4)
    {
        PickerListViewController *pickerVc = [[PickerListViewController alloc] init];
        pickerVc.isRadio = YES;
        pickerVc.index = indexPath.row;
        pickerVc.type = PreferEducation;
        [self presentViewController:pickerVc animated:YES completion:^{
            
        }];
    }
  else  if(indexPath.row == 5)
    {
        PickerListViewController *pickerVc = [[PickerListViewController alloc] init];
        pickerVc.isRadio = YES;
        pickerVc.index = indexPath.row;
        pickerVc.type = Religion;
        [self presentViewController:pickerVc animated:YES completion:^{
            
        }];
    }
}

-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
    
    return kCellHeight;
    
}

- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section
{
    
    return 0;
    
}
-(void)next:(UIButton *)btn
{
    self.maneger.lookfor = segmentLookIndex;
    self.maneger.agemin = saveAgeMin;
    self.maneger.agemax = saveAgeMax;
    self.maneger.heightmin = saveHeightMin;
    self.maneger.heightmax = saveHeightMax;
    ProdileModel *model = self.cityArray[selectCityIndex];
    self.maneger.preferLocation = model._id;
    self.maneger.preferEducation = self.preferEducation._id;
    self.maneger.preferReligion = self.religion._id;
    
    if (self.isRegister == NO) {
        NSDictionary *dic = [self getEditParameters];
        NSString *urlStr = [NSString stringWithFormat:@"%@%@",kFirstUrl,kEditPerfenrece];
        NSLog(@"urlStr:%@",urlStr);
        [DataContrller PostRequestUrl:urlStr Param:dic requestSuccess:^(NSDictionary *backDic) {
            NSLog(@"backDic:%@",backDic);
            if ([backDic[@"returnCode"] integerValue] == 200) {
                [self.navigationController popViewControllerAnimated:YES];
            } else {
                [self showAlert:backDic[@"msg"]];
            }
        } requestFail:^(NSString *backErrorStr) {
            NSLog(@"backErrorStr:%@",backErrorStr);
            [self showAlert:backErrorStr];
            
        }];
        return ;
    }
    
    NSDictionary *parameters = [self setParameters];
    NSString *urlStr = [NSString stringWithFormat:@"%@%@",kFirstUrl,kRegisterUrl];
    NSLog(@"urlStr:%@",urlStr);
    [DataContrller PostRequestUrl:urlStr Param:parameters requestSuccess:^(NSDictionary *backDic) {
        NSLog(@"backDic:%@",backDic);
        if ([backDic[@"returnCode"] integerValue] == 200) {
            WaitForAuditViewController *waitVc = [[WaitForAuditViewController alloc] init];
            self.maneger = nil;
            [self.navigationController pushViewController:waitVc animated:YES];
        } else {
            [self showAlert:backDic[@"msg"]];
        }
    } requestFail:^(NSString *backErrorStr) {
        
        NSLog(@"backErrorStr:%@",backErrorStr);
        [self showAlert:backErrorStr];
        
    }];
}

- (NSDictionary *)setParameters {
    NSMutableDictionary *parameters = [NSMutableDictionary dictionary];
    if (self.maneger.phone != nil) {
        [parameters setObject:self.maneger.phone forKey:@"phone"];
    }
    [parameters setObject:self.maneger.areaCode forKey:@"areaCode"];
    [parameters setObject:@(self.maneger.sex) forKey:@"sex"];
    if (self.maneger.username != nil) {
        [parameters setObject:self.maneger.username forKey:@"username"];
        [parameters setObject:self.maneger.realname forKey:@"realname"];
    }
    if (self.maneger.password != nil) {
        [parameters setObject:self.maneger.password forKey:@"password"];
    }
    if (self.maneger.email != nil) {
        [parameters setObject:self.maneger.email forKey:@"email"];
    }
    [parameters setObject:@(self.maneger.age) forKey:@"age"];
    //照片
    if (self.maneger.photoIds.count != 0) {
        NSMutableString *photoString = [NSMutableString string];
        for (int i=0; i<self.maneger.photoIds.count; i++) {
            if (i == self.maneger.photoIds.count - 1) {
                [photoString appendString:[NSString stringWithFormat:@"%@", self.maneger.photoIds[i]]];
            } else {
                [photoString appendString:[NSString stringWithFormat:@"%@;", self.maneger.photoIds[i]]];
            }
        }
        if (photoString != nil) {
            [parameters setObject:photoString forKey:@"photoIds"];
        }
    }
    if (self.maneger.aboutme != nil) {
        [parameters setObject:self.maneger.aboutme forKey:@"aboutme"];
    }
    [parameters setObject:@(self.maneger.sex) forKey:@"sex"];
    [parameters setObject:@(self.maneger.height) forKey:@"height"];
    [parameters setObject:@(self.maneger.single) forKey:@"single"];
    if (self.maneger.religion != nil) {
        [parameters setObject:self.maneger.religion forKey:@"religion"];
    }
    //职业
    if (self.maneger.professionsArray.count != 0) {
        NSMutableString *professionsString = [NSMutableString string];
        for (int i=0; i<self.maneger.professionsArray.count; i++) {
            if (i == self.maneger.professionsArray.count - 1) {
                [professionsString appendString:[NSString stringWithFormat:@"%@", self.maneger.professionsArray[i]]];
            } else {
                [professionsString appendString:[NSString stringWithFormat:@"%@;", self.maneger.professionsArray[i]]];
            }
        }
        if (professionsString != nil) {
            [parameters setObject:professionsString forKey:@"professions"];
        }
    }
    //教育
    if (self.maneger.educationsArray.count != 0) {
        NSMutableString *educationsString = [NSMutableString string];
        for (int i=0; i<self.maneger.educationsArray.count; i++) {
            if (i == self.maneger.educationsArray.count - 1) {
                [educationsString appendString:[NSString stringWithFormat:@"%@", self.maneger.educationsArray[i]]];
            } else {
                [educationsString appendString:[NSString stringWithFormat:@"%@;", self.maneger.educationsArray[i]]];
            }
        }
        if (educationsString != nil) {
            [parameters setObject:educationsString forKey:@"educations"];
        }
    }
    //兴趣
    if (self.maneger.interestsArray.count != 0) {
        NSMutableString *interestsString = [NSMutableString string];
        for (int i=0; i<self.maneger.interestsArray.count; i++) {
            if (i == self.maneger.interestsArray.count - 1) {
                [interestsString appendString:[NSString stringWithFormat:@"%@", self.maneger.interestsArray[i]]];
            } else {
                [interestsString appendString:[NSString stringWithFormat:@"%@;", self.maneger.interestsArray[i]]];
            }
        }
        if (interestsString != nil) {
            [parameters setObject:interestsString forKey:@"interests"];
        }
    }
    [parameters setObject:@(self.maneger.lookfor) forKey:@"lookfor"];
    [parameters setObject:@(self.maneger.agemin) forKey:@"agemin"];
    [parameters setObject:@(self.maneger.agemax) forKey:@"agemax"];
    [parameters setObject:@(self.maneger.heightmin) forKey:@"heightmin"];
    [parameters setObject:@(self.maneger.heightmax) forKey:@"heightmax"];
    if (self.maneger.location != nil) {
        [parameters setObject:self.maneger.location forKey:@"location"];
    }
    if (self.maneger.preferLocation != nil) {
        [parameters setObject:self.maneger.preferLocation forKey:@"preferLocation"];
    }
    if (self.maneger.preferEducation != nil) {
        [parameters setObject:self.maneger.preferEducation forKey:@"preferEducation"];
    }
    if (self.maneger.preferReligion != nil) {
        [parameters setObject:self.maneger.preferReligion forKey:@"preferReligion"];
    }
    NSString *lan = [InternationalControl userLanguage];
    if([lan isEqualToString:@"en"]){//判断当前的语言，进行改变
        [parameters setObject:@(1) forKey:@"systemLanguage"];
    } else {
        [parameters setObject:@(0) forKey:@"systemLanguage"];
    }
    return parameters;
}

- (NSDictionary *)getEditParameters {
    NSMutableDictionary *parameters = [NSMutableDictionary dictionary];
    [parameters setObject:[UserInfomation shareManager].pk forKey:@"pk"];
    [parameters setObject:@(self.maneger.lookfor) forKey:@"sex"];
    [parameters setObject:@(self.maneger.agemin) forKey:@"agemin"];
    [parameters setObject:@(self.maneger.agemax) forKey:@"agemax"];
    [parameters setObject:@(self.maneger.heightmin) forKey:@"heightmin"];
    [parameters setObject:@(self.maneger.heightmax) forKey:@"heightmax"];
    if (self.maneger.preferLocation != nil) {
        [parameters setObject:self.maneger.preferLocation forKey:@"preferLocation"];
    }
    if (self.maneger.preferEducation != nil) {
        [parameters setObject:self.maneger.preferEducation forKey:@"preferEducation"];
    }
    if (self.maneger.preferReligion != nil) {
        [parameters setObject:self.maneger.preferReligion forKey:@"preferReligion"];
    }
    NSString *lan = [InternationalControl userLanguage];
    if([lan isEqualToString:@"en"]){//判断当前的语言，进行改变
        [parameters setObject:@(1) forKey:@"systemLanguage"];
    } else {
        [parameters setObject:@(0) forKey:@"systemLanguage"];
    }
    return parameters;
}

-(void)change:(UISegmentedControl *)sender{
    
    if (sender.tag == 100) {
        segmentLookIndex = sender.selectedSegmentIndex;
    }
    else
    {
        segmentDistanceIndex = sender.selectedSegmentIndex;
    }
}
-(void)rangeSlider:(TTRangeSlider *)sender didChangeSelectedMinimumValue:(float)selectedMinimum andMaximumValue:(float)selectedMaximum{

//     selectedMinimum= selectedMinimum;
//    selectedMaximum = saveAgeMax;
//
//    saveHeightMin = selectedMinimum;
//    saveHeightMax = selectedMaximum;
    if (sender.tag == 1) {

        saveAgeMin = selectedMinimum;
        saveAgeMax = selectedMaximum;

        NSLog(@"1-%@ , %@",@(saveAgeMin) , @(saveAgeMax));
    }
    else
    {
        saveHeightMin = selectedMinimum;
        saveHeightMax = selectedMaximum;
        NSLog(@"2-%@ , %@",@(saveHeightMin) , @(saveHeightMax));
    }
}
- (void)PGGDropView:(PGGDropView *)DropView didSelectAtIndex:(NSInteger )index{
    
    NSLog(@"%ld",index);
    NSInteger ind = index - 100;
    
    selectCityIndex = ind;
//    cityNameLab = cityList[ind];
    [self.setupTableView reloadData];
}
- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}



@end
